package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.SetmealDishMapper;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/setmeal")
@Api(tags = "C端套餐浏览接口")
public class UserSetmealController {

    @Resource
    private SetmealService setmealService;

    @Resource
    private SetmealDishMapper setmealDishMapper;

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @ApiOperation("根据分类id查询套餐")
    @GetMapping("list")
    @Cacheable(cacheNames = "setmeal_cache", key = "'setmeal:'+#categoryId")
    public Result<List<Setmeal>> byCategoryId(@RequestParam Long categoryId) {
        List<Setmeal> categoryIdList =  setmealService.getByCategoryId(categoryId);
        return Result.success(categoryIdList);
    }


    @RequestMapping("/user/setmeal/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品")
    public Result<List<SetmealDish>> bySetmealId(@PathVariable("id") Long setmealId) {
        List<SetmealDish> bySetmealId = setmealDishMapper.getBySetmealId(setmealId);
        return Result.success(bySetmealId);
    }
}
